#include <iostream>
#include <map>
#include <string>
using namespace std;

const int N = 40010; //因为要用x+n表示x为奇数，所以这里要翻一倍

int n, m;
int a, b;
string op;
int p[N];
map<int, int> Hash;
int idx = 0;
int k;

int find(int x)
{
    if (x == p[x])
        return x;
    return p[x] = find(p[x]);
}

int main()
{
    freopen("cin.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= 4 * m; ++i) //初始化并查集
        p[i] = i;
    for (k = 0; k < m; ++k)
    {
        cin >> a >> b >> op;
        if (!Hash.count(a - 1))
        {
            Hash[a - 1] = idx;
            a = idx++;
        }
        else
            a = Hash[a - 1];
        if (!Hash.count(b))
        {
            Hash[b] = idx;
            b = idx++;
        }
        else
            b = Hash[b];
        if (op[0] == 'e') //相同
        {
            int pa = find(a), pb = find(b), p_a = find(a + 2 * m), p_b = find(b + 2 * m);
            if (pa == p_b || pb == p_a) //有矛盾
                break;
            p[pa] = pb;
            p[p_a] = p_b;
        }
        else //不同
        {
            int pa = find(a), pb = find(b), p_a = find(a + 2 * m), p_b = find(b + 2 * m);
            if (pa == pb || p_b == p_a) //有矛盾
                break;
            p[pa] = p_b;
            p[p_a] = pb;
        }
    }
    cout << k;
    return 0;
}